2020-2021 Sunseeker Telemetry and Lighting System
pmm_Reset_LPMx_5.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // MSP430FR59xx PMM Test
34 // This example shows transitions between a user Reset via the reset button, a
35 // software triggered BOR, a previous LPMx.5 state indicator flag, and entrance
36 // into LPM4.5. Reading the reset interrupt flag from PMMIFG register is equivalent
37 // to reading from reset vector register.
38 //
39 // Upon device power on you will see the following sequence of LED's
40 // X = off
41 // O = on
42 //
43 // _0 = On indicates BOR
44 // _6 = On indicates Reset (from user button)
45 // _5 = on indicates device was previously in LPMx.5 state before the reset
46 // _4 = On indicates device is NOT sleeping. Off means device is in LPM4.5
47 //*******************************************************************************
48 //
49 // 1) Power on device:
50 // X0 X6 X5 O4 LED4 is on, device is running and was not in LPM4.5 mode previously.
51 //
52 // 2) Press User Reset button:
53 //
54 // X0 O6 X5 O4 Device is running and has reset due to RST pin
55 // O0 X6 X5 O4 Device is running and has reset due to a software BOR
56 // X0 X6 X5 X4 Device is now in LPM4.5
57 //
58 // 3) Press User Reset button:
59 // Device will restart the sequence beginning at step 2).
60 //
61 //
62 //********************************************************************************
63 #include "driverlib.h"
64 
65 void main(void)
66 {
67  //Stop WDT
68  WDT_A_hold(WDT_A_BASE);
69 
70  /*
71  * Base Address of PMM,
72  * By default, the pins are unlocked unless waking
73  * up from an LPMx.5 state in which case all GPIO
74  * are previously locked.
75  *
76  */
77  PMM_unlockLPM5();
78  //Set P3.4, 3.5, 3.6, 3.0 as output pins.
79  /*
80 
81  * Select Port 3
82  * Set Pin 4, 5, 6, 0 as output
83  */
84  GPIO_setAsOutputPin(
85  GPIO_PORT_P3,
86  GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN0
87  );
88  //Set P3.5, 3.6, 3.0 Low.
89  /*
90 
91  * Select Port 3
92  * Set Pin 5, 6, 0 as Low
93  */
95  GPIO_PORT_P3,
96  GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN0
97  );
98  //Set P3.4 as High.
99  /*
100 
101  * Select Port 3
102  * Set Pin 4 as High
103  */
105  GPIO_PORT_P3,
106  GPIO_PIN4
107  );
108 
109  if (PMM_getInterruptStatus(PMM_RST_INTERRUPT)) // Was this reset triggered by the Reset flag?
110  {
111  PMM_clearInterrupt(PMM_RST_INTERRUPT); // Clear reset flag
113  GPIO_PORT_P3,
114  GPIO_PIN6
115  );
116  __delay_cycles(1000000); // to include a visual delay.
117 
118  //Trigger a software Brown Out Reset (BOR)
119  /*
120  * Base Address of PMM,
121  * Forces the devices to perform a BOR.
122  */
123  PMM_trigBOR(); // Software trigger a BOR.
124  }
125 
126  if (PMM_getInterruptStatus(PMM_BOR_INTERRUPT)) // Was this reset triggered by the BOR flag?
127  {
128  PMM_clearInterrupt(PMM_BOR_INTERRUPT); // Clear BOR flag
130  GPIO_PORT_P3,
131  GPIO_PIN0
132  );
133  __delay_cycles(1000000); // to include a visual delay.
135  GPIO_PORT_P3,
136  GPIO_PIN4 + GPIO_PIN0
137  );
138 
139  //Disable Regulator
140  /*
141  * Base Address of PMM,
142  * Regulator is turned off when going to LPM3/4.
143  * System enters LPM3.5 or LPM4.5, respectively.
144  */
145  PMM_turnOffRegulator();
146  __bis_SR_register(LPM4_bits); // Enter LPM4.5, This automatically locks
147  // (if not locked already) all GPIO pins.
148  // and will set the LPM5 flag and set the LOCKLPM5 bit
149  // in the PM5CTL0 register upon wake up.
150  }
151 
152  while (1)
153  {
154  __no_operation(); // Don't sleep
155  }
156 }
void main(void)
__no_operation()
GPIO_setOutputHighOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
GPIO_setOutputLowOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
__delay_cycles(500000)